/**
 * @Date 2023-02-04 10:53:38
 * @Remark
 */

// lib
import _ from "lodash";
import { makeAutoObservable, toJS } from "mobx";
// config
// state
// script & methods & public
// 其它

function createList(codeMap?: StrMap): StrOptionList {
  const result: StrOptionList = [];
  if (codeMap && !_.isEmpty(codeMap)) {
    for (const key in codeMap) {
      result.push({
        code: key,
        name: codeMap[key],
      });
    }
  }
  return result;
}

class DictState {

  // 「字典」动态
  allDictList: DictDto[] = [];
  dictList: DictDto[] = [];
  dictKey: string[] = [];
  // 「字典」静态
  staticDict: any = {};
  // 「字典」前端
  statusDict: any = {
    BookStatusEnum: {
      "AVAILABLE": "可用",
      "UNAVAILABLE": "不可用",
      "DELETED": "已删除",
    },
    BorrowStatusEnum: {
      "DELIVERY": "出库中",
      "BORROWED": "借出",
      "RETURNED": "已归还",
      "OVERDUE": "逾期",
      "LOST": "丢失",
      "DAMAEGED": "污损",
      "CANCELED": "已取消",
    },
    CopyStatusEnum: {
      "AVAILABLE": "可借阅",
      "BORROWED": "已借出",
      "RESERVED": "预约中",
      "LOST": "丢失",
      "DAMAEGED": "污损",
      "DESTROYED": "已销毁",
      "MAINTENANCE": "维修中",
      "IN_STOCK": "在库",
    },
    IllegalStatusEnum:{
      "PENDING":"待支付",
      "PAYED":"已支付",
      "CANCEL":"已取消",
    },
    OrderStatusEnum:{
      "PENDING":"预约中",
      "READY":"已就绪",
      "COMPLETED":"已完成",
      "EXPIRED":"已超期",
      "CANCELED":"已取消",
    },
    UserStatusEnum:{
      "AVAILABLE":"正常",
      "UNAVAILABLE":"不可用",
      "DELETED":"已删除",
    },
    IllegalTypeEnum:{
      "EXPIRY":"逾期",
      "DAMAGE":"损坏",
      "LOST":"丢失",
    }
  };
  constructor() {
    makeAutoObservable(this);
  }

  // 「字典」前端

  get BookStatusList(): StrOptionList {
    return createList(this.statusDict.BookStatusEnum);
  }
  get BorrowStatusList(): StrOptionList {
    return createList(this.statusDict.BorrowStatusEnum);
  }
  get CopyStatusList(): StrOptionList {
    return createList(this.statusDict.CopyStatusEnum);
  }
  get IllegalStatusList(): StrOptionList {
    return createList(this.statusDict.IllegalStatusEnum);
  }
  get OrderStatusList(): StrOptionList {
    return createList(this.statusDict.OrderStatusEnum);
  }
  get UserStatusList(): StrOptionList {
    return createList(this.statusDict.UserStatusEnum);
  }
  get IllegalTypeList(): StrOptionList {
    return createList(this.statusDict.IllegalTypeEnum);
  }
  // get DeliveryStatusMap(): StrMap {
  //   return toJS(this.staticDict.DeliveryStatusEnum);
  // }
  // 「字典」动态
  setAllDictList(list: DictDto[]) {
    this.allDictList = list;
  }
  getAllDictList() {
    return toJS(this.allDictList);
  }
  getDictList() {
    return toJS(this.dictList);
  }
  setDictKey(list: string[]) {
    this.dictKey = list;
  }
  getDictKey() {
    return toJS(this.dictKey);
  }

}

export default DictState;
